import gracker.*

class BootStrap {

    def init = { servletContext ->
        def adminRole = Role.findByAuthority('ROLE_ADMIN') ?:
            new Role(authority: 'ROLE_ADMIN').save(failOnError: true)
        def userRole = Role.findByAuthority('ROLE_USER') ?:
            new Role(authority: 'ROLE_USER').save(failOnError: true)
        def user1 = User.findByUsername('admin') ?:
            new User(username: 'admin', enabled: true, password: 'pass', firstName: 'Administrator', lastName: 'Administrator', email: 'admin@avathartech.com').save(failOnError: true)
        def user2 = User.findByUsername('snunez') ?:
            new User(username: 'snunez', enabled: true, password: 'pass', firstName: 'Sixto', lastName: 'Nunez', email: 'snunez@avathartech.com').save(failOnError: true)

        UserRole.create user1, adminRole, true
        UserRole.create user2, userRole, true




        assert User.count() == 2
        assert Role.count() == 2
        assert UserRole.count() == 2
    }

    def destroy = {
    }
}
